<template>
  <div>
      <h2>当前求和为:{{sum}}</h2>
      <select v-model.number="n">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
      </select>
      <button @click="increment">+</button>&nbsp;
      <button @click="decrement">-</button>&nbsp;
      <button @click="incrementIfOdd">当前求和为奇数</button>&nbsp; 
      <button @click="incrementWait">等一等0.5秒再加+</button>
  </div>
</template>

<script>
  export default {
      name:'Count',
      data(){
          return{
              n:1,
              sum:0
          }
      },
      methods:{
           //加法运算
           increment(){
             this.sum += this.n;
           },
           //减法运算
           decrement(){
               this.sum-= this.n;
           },
           //奇数加
           incrementIfOdd(){
               if(this.sum % 2){
                   this.sum += this.n
               }
           },
           //等等再加+
           incrementWait(){
               setTimeout(()=>{
                   this.sum += this.n
               },500)
           }

      }
  }
</script>

<style scoped>
  
</style>